package com.fmy.test.modular.service.impl;

import com.fmy.test.modular.mapper.UserMapper;
import com.fmy.test.modular.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * @Auther: Mr.fmy
 * @Date: 2019/8/24 0024 17:11
 * @Description: <p></p>
 */
@Service
public class UserServiceImpl implements IUserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public Integer insert(String name) {
        return userMapper.insert(name);
    }

    @Override
    @Transactional(rollbackFor = {Exception.class})
    public Integer insertTr(String name) {
        userMapper.insert(name);
        if (1 == 1) {
            throw new RuntimeException("测试事物移除回滚");
        }
        return 0;
    }

    @Override
    public Integer listInsert(String name, IUserService userService) {
        userMapper.list();//先查询
        return userService.insert(name);//后增添、必须使用这个、否则aop拦截不到
    }

    @Override
    public List<Map<String, Object>> list() {
        return userMapper.list();
    }
}
